<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title></title>
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="component/pear/css/pear.css" />
	<link rel="stylesheet" href="component/elementUI/index.css">
	<link rel="stylesheet" href="admin/css/other/login.css" />
</head>
<!-- 代 码 结 构 -->

<body style="background-size: cover;">
	<div id="app" v-cloak>
		<div class="container">
			<form class="layui-form" action="javascript:void(0);">
				<div class="layui-form-item">
					<div class="logo"></div>
					<div style="text-align: center;font-size: 0.9rem;">
						<h1><span>多点惠农产业链交易平台</span></h1>
					</div>
					<div class="text">欢迎登录</div>
					<!-- <div class="desc">
							明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
						</div> -->
				</div>
				<el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
					<el-tab-pane label="手机号" name="first">
						<div class="layui-form-item">
							<input placeholder="请输入您注册时填写的手机号" v-model="formData.username" class="layui-input" />
							<span style="color: red;" v-cloak>{{usertishi}}</span>
						</div>
						<div class="layui-form-item" id="password">
							<input :type="passwordShow ? 'text' : 'password'" placeholder="请输入您注册时填写的密码"
								v-model="formData.password" class="layui-input" />
							<span style="color: red;" v-cloak>{{passtishi}}</span>
							<div @click="passwordShow = !passwordShow">
								<img v-if="passwordShow" src="./admin/images/eye.png" alt="">
								<img v-else src="./admin/images/eyes.png" alt="">
							</div>
						</div>
						<div class="layui-form-item">
							<input @change="handleChange" type="checkbox" name="" title="记住密码" lay-skin="primary"
								:checked="remember">
						</div>
						<div class="layui-form-item">
							<el-button class="my-button" type="primary" @click="handleLogin">登 录</el-button>
						</div>
						<div>
							<span style="font-size: 12px; color: #c0c0c0;">联系我们:15046006122</span>
						</div>
					</el-tab-pane>
					<el-tab-pane label="验证码登录" name="second">
						<div style="margin: 20px;"></div>
						<el-form :label-position="labelPosition" label-width="60px" :model="formLabelAlign">
							<el-form-item label="手机号">
								<el-input v-model="formData.username"></el-input>
							</el-form-item>
							<el-form-item label="验证码">
								<el-input v-model="formLabelAlign.region">
									<el-button slot="append" :disabled="isCounting || !formData.username"
										@click="sendMessage()" icon="el-icon-position">
										{{ countdown > 0 ? countdown + 's后重新获取' : '获取验证码' }}
									</el-button>
								</el-input>
								<div style="margin-right:10%;margin-top: 10px;">
									<el-button class="my-button" @click="handleLogin()" type="primary">登 录</el-button>
								</div>
							</el-form-item>
						</el-form>
					</el-tab-pane>
				</el-tabs>
			</form>
			<el-dialog title="请选择进入的企业" :visible.sync="dialogTableVisible">
				<el-table ref="multipleTable" :data="gridData" tooltip-effect="dark" height="300px" style="width: 100%"
					@selection-change="handleSelectionChange">
					<el-table-column type="selection" width="55">
					</el-table-column>
					<el-table-column prop="Enterprise_Info_SerialNumber" label="企业编号" width="250">
					</el-table-column>
					<el-table-column prop="Enterprise_Name" label="企业名字" show-overflow-tooltip>
					</el-table-column>
				</el-table>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogTableVisible = false">取 消</el-button>
					<el-button type="primary" @click="qrqy">确 定</el-button>
				</div>
			</el-dialog>
		</div>
	</div>
	<!-- 资 源 引 入 -->
	<script type="text/javascript" src="component/layui/layui.js"></script>
	<script type="text/javascript" src="component/pear/pear.js"></script>
	<script type="text/javascript" src="utils/jquery-3.6.0.min.js"></script>
	<script type="text/javascript" src="utils/jquery.cookie.js"></script>
	<script type="text/javascript" src="utils/vue.min.js"></script>
	<script type="text/javascript" src="component/elementUI/index.js"></script>
	<script type="text/javascript" src="utils/utils.js"></script>
	<script>
		new Vue({
			el: '#app',
			data() {
				return {
					dialogTableVisible: false,
					gridData: [],
					activeName: 'first',
					countdown: 0, // 倒计时的秒数
					isCounting: false, // 用于标记是否正在倒计时
					a: {},
					labelPosition: 'right',
					loading: false,
					passwordShow: false,
					usertishi: '',
					passtishi: '',
					formData: {
						username: '',
						password: '',
						url: 'index.html',
					},
					formLabelAlign: {
						username: '',
						phone: true,
						region: ''
					},
					time: true,
					secend: 60,
					timer: null,
					remember: true
				}
			},
			mounted() {
				this.formData.password = sessionStorage.getItem("password")
				console.log(sessionStorage.getItem("password"));
				console.log(sessionStorage.getItem("User_Number"));

				this.formData.username = sessionStorage.getItem("User_Number")

			},
			methods: {
				qrqy() {
					console.log(this.multipleSelection);
					//判断只能选择一个企业进入
					if (this.multipleSelection.length == 0) {
						this.$message({
							message: '请您选择一个企业',
							type: 'warning'
						});
					} else if (this.multipleSelection.length > 1) {
						this.$message.error('您只能选择一个企业');
					} else {
						//判断是否认证了企业
						if (this.multipleSelection[0].Row_Status == "88") {
							this.$message({
								message: '已提交认证申请，等待平台审核！',
								type: 'warning'
							});
						}
						else {
							this.formData.Enterprise_Info_SerialNumber = this.multipleSelection[0].Enterprise_Info_SerialNumber
							this.formData.Enterprise_Name = this.multipleSelection[0].Enterprise_Name
							console.log(this.multipleSelection);
							console.log(this.formData)
							$.cookie('enterprise', this.formData.Enterprise_Info_SerialNumber)
							$.cookie('enterpriseName', this.formData.Enterprise_Name)
							//电话号
							sessionStorage.setItem("User_Number", this.formData.username)
							//企业编号
							sessionStorage.setItem("Enterprise_Info_SerialNumber", this.formData.Enterprise_Info_SerialNumber)
							const _this = this
							window.location.href = "./system.html";
						}

					}
				},
				handleSelectionChange(val) {
					this.multipleSelection = val;
					console.log(this.multipleSelection);
				},
				handleClick() {
					console.log(this.activeName);
					if (this.activeName == 'first') {
						this.formLabelAlign.region = ''
					}
					console.log(this.formLabelAlign.region);

				},
				handleChange() {
					console.log(this.remember)
				},
				sendMessage() {
					this.a.User_Number = this.formData.username
					sessionStorage.setItem("User_Number", this.a.User_Number)
					let a = sessionStorage.getItem("User_Number")
					console.log(a);
					// console.log(this.time);
					// console.log(this.formData.username);
					// return
					if (this.isCounting) return; // 如果正在倒计时，直接返回
					// this.countdown = 60
					this.isCounting = true;
					this.countdown = 60; // 初始化倒计时为 60 秒
					const timer = setInterval(() => {
						this.countdown--;
						if (this.countdown <= 0) {
							clearInterval(timer);
							this.isCounting = false;
						}
					}, 1000);
					$.ajax({
						header: {
							'content-type': 'application/x-www-form-urlencoded', //会将数据转换为query string
						},
						type: 'GET',
						url: 'https://service.kdddy.cn/donghui/login/getVerificationCode',
						// url: `https://marketingservice.ediblefungus.cn/send/verification/${this.formLabelAlign.name}/6/5`,
						data: {
							Telephone: a
						},
						success: (res) => {
							console.log(res);
							if (res) {
								this.$message({
									type: 'success',
									message: '发放成功！'
								});
							} else {
								this.$message({
									type: 'errer',
									message: '系统错误!请稍后重试'
								});
							}
						},
						dataType: "json"
					});
				},
				//验证码校验
				handleLogin() {
					sessionStorage.setItem("password", this.formData.password)
					console.log(this.formLabelAlign.region);
					//如果是验证码登录，识别验证码是否正确
					if (!this.formLabelAlign.region == '') {
						$.ajax({
							headers: {
								AccessToken: $.cookie("token"), //会将数据转换为query string
							},
							url: 'https://service.kdddy.cn/donghuiForRequest/User/VerificationCode',
							type: 'get',
							data: {
								User_Number: this.formData.username,
								Word: this.formLabelAlign.region,
							},
							success: function (Result) {
								console.log(Result);

							},
							dataType: "json",
						})
					}
					const _this = this
					_this.a.User_Number = _this.formData.username
					_this.a.Pass_Word = _this.formData.password
					_this.a.Word = _this.formLabelAlign.region
					//登录获取哪些公司，是否认证，获取token
					$.ajax({
						contentType: "application/json",
						// url: DomainName + '/OpenURLAction',
						// url:"https://service.kdddy.cn/donghuiwar/svysj"+ '/OpenURLAction',
						url: "https://service.kdddy.cn/donghuiForRequest/User/login",
						// url:"http://192.168.10.70:8087/User/login",
						type: 'POST',
						data: JSON.stringify(_this.a),
						success: function (arg_Result) {
							console.log(arg_Result);
							// return
							sessionStorage.setItem('User_Number', arg_Result.User_Number)
							sessionStorage.setItem('ID_Name', arg_Result.ID_Name)
							$.cookie('token', arg_Result.token)
							if (arg_Result.Status == "success") {
								console.log(arg_Result);
								_this.gridData = arg_Result.enterpise
								if (_this.gridData.length > 1) {
									_this.dialogTableVisible = true
								} else if (arg_Result.enterpise.length == 0) {
									_this.$message.error('您还没有认证企业');
								} else if (arg_Result.enterpise[0].Row_Status == "88") {
									_this.$message({
										message: '已提交认证申请，等待平台审核！',
										type: 'warning'
									});
								}  else if (arg_Result.enterpise[0].Row_Status == "77") {
									_this.$message({
										message: '该企业已注销！',
										type: 'warning'
									});
								}else {
									_this.$message({
										message: '登录成功',
										type: 'success'
									});
									console.log(arg_Result.enterpise[0].Enterprise_Info_SerialNumber);
									sessionStorage.setItem("Enterprise_Info_SerialNumber", arg_Result.enterpise[0].Enterprise_Info_SerialNumber)
									console.log(arg_Result.enterpise[0].Enterprise_Name);
									$.cookie('enterprise', arg_Result.enterpise[0].Enterprise_Info_SerialNumber)
									$.cookie('User_Number', arg_Result.User_Number)
									$.cookie('enterpriseName', arg_Result.enterpise[0].Enterprise_Name)
									window.location.href = "./system.html";
								}
							} else {
								_this.$message.error('密码输入有误或账户已注销，请检查后重新登陆');
							}
						},
						error: function (params) {
							console.log(params);
						},
						complete: function (XMLHttpRequest) {
							_this.loading = false
							$.cookie('use', XMLHttpRequest.getResponseHeader("USE"))
							$.cookie('enterprise', XMLHttpRequest.getResponseHeader("ENTERPRISE"))
							$.cookie('enterpriseName', XMLHttpRequest.getResponseHeader("ENTERPRISENAME"))
						},
					})
				},
				handleLogin1() {

					return
					if (!this.loading) {
						console.log(this.formData);
						let _this = this;
						this.usertishi = '';
						this.passtishi = '';
						if (this.formData.username == '') {
							this.usertishi = '用户名不能为空';
						} else if (this.formData.password == '') {
							this.passtishi = '密码不能为空';
						} else {
							this.loading = true
							$.ajax({
								// url: DomainName + '/OpenURLAction',
								// url:"https://service.kdddy.cn/donghuiForRequest/User/login",
								url: "https://service.kdddy.cn/donghuiForRequest/User/login",
								// url:"https://service.kdddy.cn/donghuiwar/svysj"+ '/OpenURLAction',
								type: 'POST',
								data: this.formData,
								complete: function (XMLHttpRequest) {
									_this.loading = false
									if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {

										$.cookie('token', XMLHttpRequest.getResponseHeader("Cookies"))
										$.cookie('use', XMLHttpRequest.getResponseHeader("USE"))
										$.cookie('useName', XMLHttpRequest.getResponseHeader("USERNAME"))
										// $.cookie('organize', XMLHttpRequest.getResponseHeader("ORGANIZE"))
										$.cookie('enterprise', XMLHttpRequest.getResponseHeader("ENTERPRISE"))
										$.cookie('enterpriseName', XMLHttpRequest.getResponseHeader("ENTERPRISENAME"))
										console.log(decodeURI($.cookie('enterpriseName')));
										if (XMLHttpRequest.getResponseHeader("Resuit") == 'ERROR') {
											_this.$notify.error({
												title: '错误',
												message: '账号或者密码错误'
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'RIGHTS') {
											_this.$notify.warning({
												title: '未认证',
												message: '该账号未认证,无法登陆!'
											});
											_this.$confirm('该账号未认证,无法登陆, 是否前往认证?', '提示', {
												confirmButtonText: '确定',
												cancelButtonText: '取消',
												type: 'warning'
											}).then(() => {
												window.document.location.href = 'https://marketing.ediblefungus.cn/dist/h5XKLJ/index.html#/pages/authentication/authentication'
											}).catch(() => {
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'EXAMINE') {
											_this.$notify.warning({
												title: '企业审核中',
												message: '该账号代审核中,暂时无法登陆!'
											});

										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'REFUSE') {
											_this.$notify.warning({
												title: '未通过',
												message: '该账号审核未通过,请重新注册!'
											});
										} else {
											// if(_this.remember){
											// 	localStorage.setItem("AccountPassword",JSON.stringify(_this.formData))
											// }else{
											// 	localStorage.removeItem("AccountPassword")
											// }
											_this.System(() => {
												// window.parent.document.location.href = XMLHttpRequest.getResponseHeader("Contentpath");
												window.parent.document.location.href = './system.html';
												const username = this.formLabelAlign.username
												sessionStorage.setItem(username)
												// window.history.go(-1)
											})

										}

									}
								},
								error: function (params) {
									console.log(params);
								}
							})
						}
					}
				},
				System(callback) {
					$.ajax({
						url: DomainName + '/SystemAuthority?token=' + $.cookie('token'),
						// url:"https://service.kdddy.cn/donghuiwar/svysj" + '/SystemAuthority?token=' + $.cookie('token'),
						type: 'POST',
						data: {
							User_Number: $.cookie('use'),
						},
						success: function (res) {
							console.log(res);
							$.cookie('systemData', JSON.stringify(res.Data))
							callback()
							// [{
							// 	Picture_URL: 'images/logo001.png',
							// 	System_SerialNumber: '',
							// 	System_Name: '系统数字中台',
							// 	System_Remark: '信息安全等级保护，是对信息和信息载体按照重要性等级分级别进行保护的一种工作，信息安全等级保护要求不同安全等级的信息系统应具有不同的安全保护能力。'
							// }, {
							// 	Picture_URL: 'images/logo002.png',
							// 	System_SerialNumber: '',
							// 	System_Name: '平台营销门户',
							// 	System_Remark: 'ISO 22301是第一份以业务连续管理为主题的国际标准，提供了一种完整通用的BCM方法论，让企业能够达到国际上公认的最佳实践。'
							// }, {
							// 	Picture_URL: 'images/logo003.png',
							// 	System_SerialNumber: '',
							// 	System_Name: '产业互联网综合服务后台',
							// 	System_Remark: 'ISO 22301是第一份以业务连续管理为主题的国际标准，提供了一种完整通用的BCM方法论，让企业能够达到国际上公认的最佳实践。'
							// }, {
							// 	Picture_URL: 'images/logo004.png',
							// 	System_SerialNumber: '',
							// 	System_Name: '智慧交易系统',
							// 	System_Remark: 'ISO 22301是第一份以业务连续管理为主题的国际标准，提供了一种完整通用的BCM方法论，让企业能够达到国际上公认的最佳实践。'

							// }, {
							// 	Picture_URL: 'images/logo001.png',
							// 	System_SerialNumber: '',
							// 	System_Name: '商家智慧运系统',
							// 	System_Remark: 'ISO 22301是第一份以业务连续管理为主题的国际标准，提供了一种完整通用的BCM方法论，让企业能够达到国际上公认的最佳实践。'
							// }]
						},
						error: function (params) {
							console.log(params);
						}
					})
				},
				changeView() {
					this.passwordShow = !this.passwordShow
				}
			}
		})
	</script>
</body>

</html>